package ben.samplegame;

import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import game.engine.GameRule;
import game.physics.GameVector;
import game.physics.ImpulseVector;
import game.sprite.Background;
import game.sprite.Sprite;
import game.sprite.MovableSprite;

public class GravityRule implements GameRule {
    
    public GameVector gravityAcceleration;
    private ArrayList<Sprite> myGameSprites;
    private Point gravityPoint;
   // private HashSet<Sprite> appliedSprites = new HashSet<Sprite>();
    
    public GravityRule(ArrayList<Sprite> gameSprites, Background gameBackground){
        myGameSprites = gameSprites;
        int x = gameBackground.getGameHeight()/2;
        int y = gameBackground.getGameHeight()/2;
        gravityPoint = new Point (x,y);
    }

    @Override
    public void checkRules () {
        for(Sprite s: myGameSprites){
            if(s instanceof MovableSprite){
                MovableSprite move = (MovableSprite)s;
                gravityAcceleration = new ImpulseVector(move.getCenterCoordinate(), gravityPoint, .1);
                double magnitude = gravityAcceleration.getMagnitude();
                double factor = Math.pow(magnitude, 1.5);
                gravityAcceleration.multiply(1/factor);
                //move.addExternalForce(gravityAcceleration);
                //System.out.println("applying rule");
                //appliedSprites.add(s);
            }
        }
        
        
    }

}
